package com.kfyang.manualgear.daoplugin.simple;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import com.kfyang.manualgear.daoplugin.simple.SimpleTypes;
import com.intellij.psi.TokenType;

%%

%class SimpleLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{  return;
%eof}

END_OF_LINE_COMMENT=("#")[^\r\n]*
KEYWORD=(“insert” | "into" | "values" | "update" | "set" | "delete" | "from" | "where" | "group" | "order" | "by" | "and" | "or" | "in" | "is" | "not" | "null")
VARIABLE_CHARACTER=[a-zA-Z0-9_\.\(\)]
FRAG_CHARACTER=[a-zA-Z0-9_]
OTHER_CHARACTER=[^\ \n\t\f!\{\}\[\],]
WHITE_SPACE=[\ \n\t\f]
SEPERATOR=[\+\-\*/=!\(\),] | "!="

%state WAITING_VALUE

%%

<YYINITIAL> {END_OF_LINE_COMMENT}                           { yybegin(YYINITIAL); return SimpleTypes.COMMENT; }

<YYINITIAL> ("`"){KEYWORD}+("`")                            { yybegin(YYINITIAL); return SimpleTypes.OTHER; }

<YYINITIAL> {KEYWORD}                                       { yybegin(YYINITIAL); return SimpleTypes.KEYWORD; }

<YYINITIAL> ("{{"){VARIABLE_CHARACTER}+("}}")               { yybegin(YYINITIAL); return SimpleTypes.IN_EXPRESSION; }

<YYINITIAL> ("{"){VARIABLE_CHARACTER}+("}")                 { yybegin(YYINITIAL); return SimpleTypes.EXPRESSION; }

<YYINITIAL> ("["){FRAG_CHARACTER}+("]")                     { yybegin(YYINITIAL); return SimpleTypes.FRAG; }

<YYINITIAL> {SEPERATOR}                                     { yybegin(YYINITIAL); return SimpleTypes.SEPARATOR; }

<YYINITIAL> {OTHER_CHARACTER}+                              { yybegin(YYINITIAL); return SimpleTypes.OTHER; }

<WAITING_VALUE> {WHITE_SPACE}+                              { yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE; }

{WHITE_SPACE}+                                              { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }

[^]                                                         { return TokenType.BAD_CHARACTER; }
